//
//  RefundHintView.m
//  JinFuThree
//
//  Created by 毛韶谦 on 2018/9/12.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "RefundHintView.h"

@interface RefundHintView ()

@property (nonatomic, strong) UIButton *cancleBtn;
@property (nonatomic, strong) UIButton *sureBtn;

@end

@implementation RefundHintView


- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.cornerRadius = 10;
        self.layer.masksToBounds = YES;
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.mas_equalTo(self);
            make.height.mas_equalTo(55);
        }];
        UIImageView *lineImageView = [[UIImageView alloc] init];
        lineImageView.backgroundColor = ThemeMaoLineColor;
        [self addSubview:lineImageView];
        [lineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.right.mas_equalTo(self.titleLabel);
            make.height.mas_equalTo(0.5);
        }];
        
        [self.leftLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.mas_left).offset(20);
            make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(20);
        }];
        [self.leftLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.leftLabel1);
            make.top.mas_equalTo(self.leftLabel1.mas_bottom).offset(19);
        }];
        [self.leftLabel3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.leftLabel2);
            make.top.mas_equalTo(self.leftLabel2.mas_bottom).offset(19);
        }];
        [self.leftLabel4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.leftLabel3);
            make.top.mas_equalTo(self.leftLabel3.mas_bottom).offset(19);
        }];
        [self.leftLabel5 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.leftLabel4);
            make.top.mas_equalTo(self.leftLabel4.mas_bottom).offset(19);
        }];
        [self.leftLabel6 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.leftLabel5);
            make.top.mas_equalTo(self.leftLabel5.mas_bottom).offset(19);
        }];
        
        [self.rightLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.mas_right).offset(-20);
            make.centerY.mas_equalTo(self.leftLabel1.mas_centerY);
        }];
        [self.rightLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.rightLabel1);
            make.centerY.mas_equalTo(self.leftLabel2.mas_centerY);
        }];
        [self.rightLabel3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.rightLabel1);
            make.centerY.mas_equalTo(self.leftLabel3.mas_centerY);
        }];
        [self.rightLabel4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.rightLabel1);
            make.centerY.mas_equalTo(self.leftLabel4.mas_centerY);
        }];
        [self.rightLabel5 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.rightLabel1);
            make.centerY.mas_equalTo(self.leftLabel5.mas_centerY);
        }];
        [self.rightLabel6 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.rightLabel1);
            make.centerY.mas_equalTo(self.leftLabel6.mas_centerY);
        }];
        
        
        [self.cancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.mas_left).offset(15);
            make.bottom.mas_equalTo(self.mas_bottom).offset(-20);
            make.right.mas_equalTo(self.sureBtn.mas_left).offset(-15);
            make.height.mas_equalTo(44);
        }];
        [self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(44);
            make.width.mas_equalTo(self.cancleBtn.mas_width);
            make.right.mas_equalTo(self.mas_right).offset(-15);
            make.bottom.mas_equalTo(self.mas_bottom).offset(-20);
        }];
        
        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.colors = @[(__bridge id)HexColor(0xD6C096).CGColor, (__bridge id)HexColor(0xBEA471).CGColor];
        gradientLayer.locations = @[@0, @1];
        gradientLayer.startPoint = CGPointMake(0, 1);
        gradientLayer.endPoint = CGPointMake(1, 1);
        gradientLayer.frame = CGRectMake(0, 0, (CGRectGetWidth(frame)-45.f)/2.f, 44);
        gradientLayer.cornerRadius = 2;
        gradientLayer.masksToBounds = YES;
        [self.sureBtn.layer addSublayer:gradientLayer];
        
        UILabel *label = [[UILabel alloc] init];
        label.text = @"确定";
        label.textColor = [UIColor whiteColor];
        label.font = [UIFont boldSystemFontOfSize:15];
        [self.sureBtn addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.centerY.mas_equalTo(self.sureBtn);
        }];
    }
    
    return self;
}

- (void)updateInfo {
    
    self.titleLabel.text = @"还款信息确认";
    self.rightLabel1.text = @"苹果iPhone8 64G 黑色";
    self.rightLabel2.text = @"5000.00元";
    self.rightLabel3.text = @"4000.00元";
    self.rightLabel4.text = @"1000.00元";
    self.rightLabel5.text = @"第一期";
    self.rightLabel6.text = @"833.33";
}


- (void)sureBtnAction {
    
    if ([self.delegate respondsToSelector:@selector(ClickSureBtnAction)]) {
        
        [self.delegate ClickSureBtnAction];
        UIView *backgroundView = self.superview;
        
        [UIView animateWithDuration:0.3 animations:^{
            
            backgroundView.alpha = 0;
        } completion:^(BOOL finished) {
            backgroundView.hidden = YES;
            [backgroundView removeFromSuperview];
        }];
    }
    
}

- (void)cancelBtnAction {
    
    UIView *backgroundView = self.superview;
    
    [UIView animateWithDuration:0.3 animations:^{
        
        backgroundView.alpha = 0;
    } completion:^(BOOL finished) {
        backgroundView.hidden = YES;
        [backgroundView removeFromSuperview];
    }];
    
}


- (UIButton *)cancleBtn {
    
    if (!_cancleBtn) {
        _cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _cancleBtn.layer.cornerRadius = 2;
        _cancleBtn.layer.masksToBounds = YES;
        [_cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
        _cancleBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_cancleBtn setTitleColor:HexColor(0x333333) forState:UIControlStateNormal];
        [_cancleBtn addTarget:self action:@selector(cancelBtnAction) forControlEvents:UIControlEventTouchUpInside];
        _cancleBtn.backgroundColor = HexColor(0xF2F2F2);
        
        [self addSubview:_cancleBtn];
    }
    return _cancleBtn;
}
- (UIButton *)sureBtn {
    
    if (!_sureBtn) {
        _sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _sureBtn.layer.cornerRadius = 2;
        _sureBtn.layer.masksToBounds = YES;
        [_sureBtn addTarget:self action:@selector(sureBtnAction) forControlEvents:UIControlEventTouchUpInside];

        [self addSubview:_sureBtn];
    }
    return _sureBtn;
}


- (UILabel *)titleLabel {
    
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        [_titleLabel setTextAlignment:NSTextAlignmentCenter];
        _titleLabel.textColor = HexColor(0x333333);
        _titleLabel.font = [UIFont boldSystemFontOfSize:15];
        
        [self addSubview:_titleLabel];
    }
    return _titleLabel;
}
- (UILabel *)leftLabel1 {
    
    if (!_leftLabel1) {
        _leftLabel1 = [[UILabel alloc] init];
        _leftLabel1.font = [UIFont systemFontOfSize:14];
        _leftLabel1.textColor = HexColor(0x666666);
        _leftLabel1.text = @"商品名称";
        
        [self addSubview:_leftLabel1];
    }
    return _leftLabel1;
}
- (UILabel *)leftLabel2 {
    
    if (!_leftLabel2) {
        _leftLabel2 = [[UILabel alloc] init];
        _leftLabel2.font = [UIFont systemFontOfSize:14];
        _leftLabel2.textColor = HexColor(0x666666);
        _leftLabel2.text = @"商品价格";
        
        [self addSubview:_leftLabel2];
    }
    return _leftLabel2;
}
- (UILabel *)leftLabel3 {
    
    if (!_leftLabel3) {
        _leftLabel3 = [[UILabel alloc] init];
        _leftLabel3.font = [UIFont systemFontOfSize:14];
        _leftLabel3.textColor = HexColor(0x666666);
        _leftLabel3.text = @"贷款金额";
        
        [self addSubview:_leftLabel3];
    }
    return _leftLabel3;
}
- (UILabel *)leftLabel4 {
    
    if (!_leftLabel4) {
        _leftLabel4 = [[UILabel alloc] init];
        _leftLabel4.font = [UIFont systemFontOfSize:14];
        _leftLabel4.textColor = HexColor(0x666666);
        _leftLabel4.text = @"首付金额";
        
        [self addSubview:_leftLabel4];
    }
    return _leftLabel4;
}
- (UILabel *)leftLabel5 {
    
    if (!_leftLabel5) {
        _leftLabel5 = [[UILabel alloc] init];
        _leftLabel5.font = [UIFont systemFontOfSize:14];
        _leftLabel5.textColor = HexColor(0x666666);
        _leftLabel5.text = @"还款期数";
        
        [self addSubview:_leftLabel5];
    }
    return _leftLabel5;
}
- (UILabel *)leftLabel6 {
    
    if (!_leftLabel6) {
        _leftLabel6 = [[UILabel alloc] init];
        _leftLabel6.font = [UIFont systemFontOfSize:14];
        _leftLabel6.textColor = HexColor(0x666666);
        _leftLabel6.text = @"应还金额";
        
        [self addSubview:_leftLabel6];
    }
    return _leftLabel6;
}

- (UILabel *)rightLabel1 {
    
    if (!_rightLabel1) {
        _rightLabel1 = [[UILabel alloc] init];
        _rightLabel1.font = [UIFont systemFontOfSize:14];
        _rightLabel1.textColor = ThemeMaoColor;
        
        [self addSubview:_rightLabel1];
    }
    return _rightLabel1;
}
- (UILabel *)rightLabel2 {
    
    if (!_rightLabel2) {
        _rightLabel2 = [[UILabel alloc] init];
        _rightLabel2.font = [UIFont systemFontOfSize:14];
        _rightLabel2.textColor = HexColor(0x333333);
        
        [self addSubview:_rightLabel2];
    }
    return _rightLabel2;
}
- (UILabel *)rightLabel3 {
    
    if (!_rightLabel3) {
        _rightLabel3 = [[UILabel alloc] init];
        _rightLabel3.font = [UIFont systemFontOfSize:14];
        _rightLabel3.textColor = HexColor(0x333333);
        
        [self addSubview:_rightLabel3];
    }
    return _rightLabel3;
}
- (UILabel *)rightLabel4 {
    
    if (!_rightLabel4) {
        _rightLabel4 = [[UILabel alloc] init];
        _rightLabel4.font = [UIFont systemFontOfSize:14];
        _rightLabel4.textColor = HexColor(0x333333);
        
        [self addSubview:_rightLabel4];
    }
    return _rightLabel4;
}
- (UILabel *)rightLabel5 {
    
    if (!_rightLabel5) {
        _rightLabel5 = [[UILabel alloc] init];
        _rightLabel5.font = [UIFont systemFontOfSize:14];
        _rightLabel5.textColor = HexColor(0x333333);
        
        [self addSubview:_rightLabel5];
    }
    return _rightLabel5;
}
- (UILabel *)rightLabel6 {
    
    if (!_rightLabel6) {
        _rightLabel6 = [[UILabel alloc] init];
        _rightLabel6.font = [UIFont systemFontOfSize:14];
        _rightLabel6.textColor = HexColor(0x333333);
        
        [self addSubview:_rightLabel6];
    }
    return _rightLabel6;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
